<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>tab</title>
        <link rel="stylesheet" href="tab.css">
</head>
<body>
    <div class="tab">
        <div class="tab_list">
            <ul>
                <li class="current">商品介绍</li>
                <li>规格与包装</li>
                <li>售后保障</li>
                <li>商品评价</li>
                <li>手机社区</li>
            </ul>
        </div>
        <div xyz="xyz" class="tab_con">
            <div class="item" style="display: block;">商品介绍模块内容</div>
            <div class="item" style="display: none;">规格与包装模块内容</div>
            <div class="item" style="display: none;">售后保障模块内容</div>
            <div class="item" style="display: none;">商品评价模块内容</div>
            <div class="item" style="display: none;">手机社区模块内容</div>
        </div>
    </div>
<script>
    var lis =document.querySelectorAll('.tab_list li');
    var items=document.querySelectorAll('.item');
    for(var i=0;i<lis.length;i++){
        lis[i].setAttribute('index',i);
        lis[i].onclick=changeTab;
    }
    console.log("外层："+this);
    window.text()
    function changeTab(){
        console.log(this);
        for (var j=0;j< lis.length;j++){
            if(lis[j] !== this){
            lis[j].className='';
        } else {
            this.className ='current';
        }
    }
var index = this.getAttribute('index');
                for (var i = 0; i < items.length; i++) {
                    if(items[i] !== items[index]){
                    items[i].style.display = 'none';
                } else {
                items[index].style.display = 'block';
            }
        }
    }
</script>
</body>
</html>
